import csv
data = [
    ("测试1",'软件测试工程师'),
    ("测试2",'软件测试工程师'),
    ("测试3",'软件测试工程师'),
    ("测试4",'软件测试工程师'),
    ("测试5",'软件测试工程师5'),
]

"""
123
写入csv数据，newline=''不空行写入
1，打开文件，通过csv.writer(文件名)继续写入操作
2，通过for循环的方式将数据循环写入到对应的文件
"""
path= r'../../Pagoda2022/PAGODA/data/test_csv12345.csv'
# f=open(path,'a+',encoding='utf-8',newline='')
# wself=csv.writer(f)
# for one in data:
#     print(one)
#     csv.writer(f)
#     wself.writerow(one)



with open(path,'a+',newline='',encoding='utf-8')as f:
    writer = csv.writer(f)
    # print(writer)
    for one in data: #循环要写入到的数据
        # print(one)
        writer.writerow(one)#一行一行的写入



    # for i in data:
    #     writer.writerow(i)
    # f.close()


"""读取csv数据"""
# aaa="./data/test.csv"
# with open(aaa,encoding='utf-8')as fo:
#     f=csv.reader(fo)
#     for one in f:
#         print(one)

bookpath="./data/book.csv"
book="./data/newbook.csv"
rlist=[]
#open(book,'a+',newline='',encoding='utf-8')as fo:
with open(bookpath,encoding='utf-8')as read,open(book,'a+',newline='',encoding='utf-8')as fo:
    f=csv.reader(read)
    writer = csv.writer(fo)
    for i in f:
        if "价格" not in i[2]:
            if int(i[2])>=80:
                print(i)
                csv.writer(fo)
                writer.writerow(i)







        # print((i[2]))
        # if int(i[2])>=80:
        #     print(i)
    # print(rlist)

# f=csv.reader(open(aaa,'r',encoding='utf-8'))
# for one in f:
#     print(one)


# rowlist=[]
# for myread in f:
#     print(myread)
#     # print(myread[0],myread[1])
#     list=myread[0]+myread[1]
#     rowlist.append(list)
# print(rowlist)

# f = open(aaa, 'r', encoding='utf-8')
# reader = csv.DictReader(f)
# for i in reader:
#     print(i)
# f.close()

#
# data = {'id':'123','name':'anjing','age':'26'}
# with open('D:/123.csv','w',newline='')as f:
#     fieldnames = {'id','name','age'}    # 表头
#     writer = csv.DictWriter(f,fieldnames=fieldnames)
#     writer.writeheader()
#     writer.writerow(data)

#
# data = {'id':'123','name':'anjing','age':'26'}
# # 加入参数“enwline=''”
# with open('123.csv','w',newline='')as f:
#     fieldnames = {'id','name','age'}
#     writer = csv.DictWriter(f,fieldnames=fieldnames)
#     writer.writeheader()
#     writer.writerow(data)
